package com.yusi.controller;


import com.yusi.entity.FlightLine;
import com.yusi.entity.dto.RespBean;
import com.yusi.service.IFlightLineService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yusi
 * @since 2022-01-11
 */
@RestController
@RequestMapping("/flight/info")
public class FlightLineController {
    @Autowired
    private IFlightLineService iFlightLineService;

    @ApiOperation("获取机票信息")
    @GetMapping("/")
    public List<FlightLine> getFlightLine(){
        return iFlightLineService.getFlightLine();
    }
    @ApiOperation("新增机票信息")
    @PostMapping("/")
    public RespBean setFlightLine(@RequestBody FlightLine flightLine){
        if (iFlightLineService.save(flightLine)){
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }
    @ApiOperation("修改机票信息")
    @PutMapping("/")
    public RespBean updFlightLine(@RequestBody FlightLine flightLine){
        if (iFlightLineService.updateById(flightLine)){
            return   RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public RespBean delFlightLine(@PathVariable Integer id){
        if (iFlightLineService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");

    }

}
